var prefix = ctx + "ce/quota"
$(function() {
	initLoadBusiId();
	validateRule();
});
$.validator.setDefaults({
	submitHandler : function() {
		submit01();
	}
});
function submit01() {
	$.ajax({
		cache : true,
		type : "POST",
		url : prefix + "/save",
		data : $('#signupForm').serialize(),
		async : false,
		error : function(request) {
			laryer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("保存成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				layer.alert(data.msg)
			}
		}
	});
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			quotaName : {
				required : true
			}
		},
		messages : {
			quotaName : {
				required : icon + "请输入指标名称"
			}
		}
	})
}
/**
 * 初始化业务元指标
 */
function initLoadBusiId(){
		var html = "";
		var modelType = $('#modelType').val();
		$.ajax({
			url : ctx + "md/business/getByDataType",
			data : {
				'modelType' : modelType
			},
			success : function(data) {
				$("#busiId").html('<option value="">--请选择业务元指标--</option>');
				//加载数据
				for (var i = 0; i < data.length; i++) {
					html += '<option value="' + data[i].busiId + '">' + data[i].busiName + '</option>'
				}
				$("#busiId").append(html);
				$("#busiId").chosen('destroy').chosen({
					maxHeight : 200,
					search_contains: true
				});
			}
		}); 
}